import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: mac
 * Date: 2022-08-19
 * Time: 8:23
 */
public class RecursionWorkDemo {
    //1.求最大值方法的重载
    public static int max(int a, int b) {
        return a > b ? a : b;
    }

    public static double max(double a, double b) {
        return a > b ? a : b;
    }

    public static double max(double a, double b, double c) {
        return max(a, b) > c ? max(a, b) : c;
    }

    public static void main1(String[] args) {
        System.out.println(max(1, 2));
        System.out.println(max(1.1, 1.2, -2.3));
    }

    //2.求和的重载
    public static int add(int a, int b) {
        return a + b;
    }

    public static double add(double a, double b, double c) {
        return a + b + c;
    }

    public static void main2(String[] args) {
        System.out.println(add(1, 2));
        System.out.println(add(1.2, 1.3, 1.4));
    }

    //3.青蛙跳台阶问题
    public static int frogjump(int n) {
        if (n == 1 || n == 2) {
            return n;
        }
        int f1 = 1;
        int f2 = 2;
        int f3 = 0;
        for (int i = 3; i <= n; i++) {
            f3 = f1 + f2;
            f1 = f2;
            f2 = f3;
        }
        return f3;
    }

    public static void main3(String[] args) {
        System.out.println(frogjump(1));
        System.out.println(frogjump(3));
        System.out.println(frogjump(4));
    }

    //4.递归求解汉诺塔问题
    public static void hanoi(char a, char b, char c, int n) {
        int count = 0;
        if (1 == n) {
            System.out.println(a + "->" + c);
            count++;
        } else {
            hanoi(a, c, b, n - 1);
            System.out.println(a + "->" + c);
            hanoi(b, a, c, n - 1);
            count++;
        }
    }

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("汉诺塔问题：现有三个柱子A，B，C");
        System.out.println("请输入圆盘个数：");
        while (scanner.hasNextInt()) {
            int n = scanner.nextInt();
            System.out.println("当A上面圆盘个数为" + n + "时");
            System.out.println("具体实现细节为：");
            int count = 0;

            hanoi('a', 'b', 'c', n);
            int ret = 1;
            for (int i = 0; i < n; i++) {
                ret *= 2;
            }
            System.out.println("***************");
            System.out.println("总的移动次数为：" + (ret - 1));
            System.out.println("***************");
        }
    }

    //5.递归求斐波那契数列的第 N 项
    public static int fib(int n) {
        if (n == 1 || n == 2) {
            return 1;
        }
        return fib(n - 1) + fib(n - 2);
    }

    public static void main5(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextInt()) {
            int n = scanner.nextInt();
            int ret = fib(n);
            System.out.println(ret);
        }
    }

    //6.返回的数字之和
    public static int sumAdd(int n){
        if (n < 10){
            return n;
        }
        return n % 10 + sumAdd(n / 10);
    }
    public static void main6(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextInt()) {
            int n = scanner.nextInt();
            int ret = sumAdd(n);
            System.out.println(ret);
        }
    }

    //7.递归打印数字的每一位
    public static void myprint(int n){
        if (n < 10){
            System.out.print(n + " ");
            return;
        }
        myprint(n / 10);
        System.out.print(n % 10 + " ");
    }
    public static void main7(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextInt()) {
            int n = scanner.nextInt();
            myprint(n);
        }
    }

    //8.递归求和
    public static int sumBdd(int n){
        if (n == 1){
            return 1;
        }
        return n + sumBdd(n - 1);
    }
    public static void main8(String[] args) {
        System.out.println(sumBdd(10));
    }

    //9.递归求 N 的阶乘
    public static int func(int n){
        if (n == 1){
            return n;
        }
        return n * func(n - 1);
    }
    public static void main9(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNextInt()) {
            int n = scanner.nextInt();
            int ret = func(n);
            System.out.println(ret);
        }
    }
}
